<template>
    <div>
        <el-card style="border:none !important;border-radius: 12px;box-shadow:none !important">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/userhome' }">个人中心</el-breadcrumb-item>
                <el-breadcrumb-item>
                    <a href="/user_collect">素材管理</a>
                </el-breadcrumb-item>
                <el-breadcrumb-item>我的收藏</el-breadcrumb-item>
            </el-breadcrumb>
            <div class="tab-nav-bd">
                <span class="title">我的收藏</span>
            </div>
        </el-card>
        <div class="main-box" style=" margin-top: 20px;">
            <div class="filter filter-hd"><el-input style="max-width: 600px" placeholder="请输入关键词">
                    <template #append>搜索</template>
                </el-input></div>
            <div class="model-content">
                <div class="model-list-box" style="min-height: 607px;">
                    <ul class="fav-model-list">
                        <li v-for="(item, index) in collectList" :key="index">
                            <div class="move-box">
                                <a class="model-a-css model-item-a" @click="productDetailClick(item['product']['id'],item['product']['ascription'])">
                                    <div class="model-img"><img :src="item['product']['full_url']"  @error.once="useDefaultImage"
                                            :alt="item['product']['title']">
                                    </div>
                                    <div class="model-item-bd f2">
                                        <span class="model-type">{{ item['product']['nav']['title'] ?? '' }}</span>
                                        <span class="model-name" style="margin-left: 6px;"> {{ item['product']['title'] }}</span>
                                    </div>
                                    <div class="model-contrast">
                                        <div class="js-model-del" :data-material-id="item['product']['product_ids']"
                                            @click.stop="productCareClick(item['product_id'])">
                                            <el-icon>
                                                <Delete />
                                            </el-icon>
                                            <span class="balloon-tips">取消收藏</span>
                                        </div>
                                    </div>
                                </a>
                            </div>
                        </li>
                    </ul>
                    <div class="not-yet-data not-data" v-if="collectList.length == 0">
                            <el-empty description="暂无数据">
                                <div class="not-data-tips">前往<a href="/" target="_blank">首页</a>逛逛吧</div>
                            </el-empty>
                 </div>
                </div>
                <div class="btm-tips">
                    <div style="display: flex;align-items: center;justify-content: center; width: 100%;">
                    <el-pagination background v-model:current-page="currentPage" v-model:page-size="pageSize"
                        layout="prev, pager, next" :total="total" @current-change="handleCurrentChange"
                        :hide-on-single-page="true" />
                </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script setup lang="ts">
import { ref, onMounted,nextTick } from 'vue';
import { myCollectList } from '../../api/user/index'
import { productCare } from '../../api/home/index'
import { encrypt, DEFAULTKEY } from '../../utils/keyEnum'
import router from '../../router'
const collectList = ref([])
import { useSiteConfig } from '../../stores/siteConfig'
const siteConf = useSiteConfig()
const currentPage = ref(1); //当前页
const pageSize = ref(10) //每页显示条目个数
const total = ref(0)
const useDefaultImage = (event:any)=>{
    event.target.src = siteConf.defalut_product_img
}
//我的收藏
const myList = () => {
    myCollectList({ limit: pageSize.value, page: currentPage.value }).then((res:any) => {
        if (res.code == 1) {
            collectList.value = res.data.list
            total.value = res.data.total
        }
    })
}

//选择页数
const handleCurrentChange = (val: number) => {
    currentPage.value = val
    myList()
}

//收藏取消收藏
const productCareClick = (id: number) => {
    productCare({ id: id }).then((res:any) => {
        if (res.code == 1) {
            myList()
        }
    })
}

//详情
const productDetailClick = (id: number,ascription:any) => {
  const queryToAse = encrypt({
    product_id: id,
    ascription: ascription
  }, DEFAULTKEY)
  nextTick(() => {
    const resolvedRoute = router.resolve({
                    name: '/product-detail',

                    query: { value: queryToAse }

                    });

                    window.open(resolvedRoute.href, '_blank');
    //router.push({ name: '/product-detail', query: { value: queryToAse } })
  });

}

onMounted(()=>{
    myList()
})
</script>
<style scoped>
.tab-nav-bd {
    margin-top: 16px;
}

.tab-nav-bd .title {
    font-size: 18px;
    font-weight: 700;
    color: #1D2129;
    line-height: 26px;
}

/* .model-content {
    height: 100%;
    overflow-y: auto;
    padding-bottom: 80px;
} */
.fav-model-list {
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -ms-flex-wrap: wrap;
    flex-wrap: wrap;
    margin-left: -15px;
    padding: 0 18px 0 24px;
}

.fav-model-list>li {
    position: relative;
    margin: 15px 0 0 15px;
    width: 245px;
}

.fav-model-list>li .model-a-css {
    display: block;
    position: relative;
    width: 100%;
    font-size: 14px;
    color: #1D2129;
    line-height: 22px;
}

.fav-model-list>li .model-a-css .model-img {
    margin-bottom: 4px;
    width: 100%;
    height: 184px;
    background: #E5E6EB;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #FF7D00;
}

.fav-model-list>li .model-a-css .model-img img {
    width: 100%;
    height: 100%;
    -webkit-transition: all 1s ease-in-out;
    transition: all 1s ease-in-out;
    border-radius: 12px;
}

.fav-model-list>li .model-a-css .model-item-bd {
    height: 22px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

.fav-model-list>li .model-a-css .model-type {
    position: relative;
    margin-right: 6px;
}

.fav-model-list>li .model-a-css .model-type::after {
    content: "";
    position: absolute;
    right: -6px;
    top: 4px;
    width: 1px;
    height: 12px;
    background-color: #86909C;
}

.fav-model-list>li .model-contrast {
    display: none;
    position: absolute;
    right: 8px;
    top: 8px;
}

.fav-model-list>li .model-contrast>div {
    position: relative;
    width: 24px;
    height: 24px;
    background: rgba(0, 0, 0, .6);
    border-radius: 6px;
    margin-bottom: 4px;
    color: #fff;
    font-size: 14px;
    line-height: 24px;
    text-align: center;
    cursor: pointer;
    -webkit-transition: left .5s, opacity .2s;
    transition: left .5s, opacity .2s;
}

.fav-model-list>li .model-contrast .balloon-tips {
    display: none;
    position: absolute;
    right: 30px;
    top: 0;
    padding: 0 6px;
    height: 26px;
    line-height: 26px;
    font-size: 12px;
    color: #fff;
    background: rgba(29, 33, 41, .9);
    border-radius: 2px;
    white-space: nowrap;
}

.fav-model-list>li .model-a-css:hover img {
    -webkit-transform: scale(1.1);
    transform: scale(1.1)
}

.fav-model-list>li:hover .model-contrast {
    display: block;
}

.fav-model-list>li .model-contrast .balloon-tips::after {
    content: "";
    border-color: transparent transparent transparent rgba(29, 33, 41, .9);
    border-width: 6px;
    border-style: solid;
    position: absolute;
    top: 6px;
    right: -12px
}

.fav-model-list>li .model-contrast>div:hover .balloon-tips {
    display: block;
    visibility: initial;
    opacity: 1;
    -webkit-transform: scale(1);
    transform: scale(1)
}

.main-box {
    padding: 0 0 20px;
    background: #FFF;
}

.model-list-box {
    min-height: 667px;
}

.main-box .filter-hd {
    padding: 20px 24px 12px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    -webkit-box-pack: justify;
    -ms-flex-pack: justify;
    justify-content: space-between;
    border-bottom: 1px solid #F2F3F5;
}

.model-content {
    /* height: 607px; */
    overflow-y: auto;
    padding-bottom: 80px;
    min-height: 607px;
}

.btm-tips {
    margin: 24px 0;
    color: #4e5969;
    text-align: center;
    font-size: 14px;
}
.not-data {
    display: block;
    margin: 0 auto 40px;
    text-align: center;
    font-size: 14px;
    color: #86909C;
    line-height: 24px;
}

.not-yet-data a {
    color: #06CD65;
}
</style>